<template>
  <div class="verifyPass">
    <van-popup position="bottom" round  v-model="isShow_VerifyPssPopup" @click-overlay='handleClosePopup' :close-on-click-overlay='false'>
     
      <verifyPasswd
        :title="$t('verify.title')"
        :btn="$t('verify.btn_OK')"
        @callback="getPayPass"></verifyPasswd>
    </van-popup>
  </div>
</template>
<script>
export default {
  props: {
    isShow_VerifyPssPopup: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      isHas_password: this.$store.state.userData.hasSetPassword, // 是否存在交易密码
      isShow_safetyVerify_Alert: false, //是否显示手机验证
      isShow_passVerify_Alert: false, //是否显示交易密码验证框
      isShow_setPass_Alert: false, //是否显示设置密码验证框
      isPass_safetyVerify: false, //是否通过安全验证
      isPass_setPass: false, //是否通过初次设置密码
      payPass: "", //交易密码
      mobileCode:'',//区号
      target:'',//target
      vcode:'',//验证码
    };
  },
  mounted() {
    console.log(111)
  },  
  computed:{

    userData(){
      return this.$store.state.userData;
    }
  },
  watch: {
    // 监听是否通过安全验证
    isPass_safetyVerify(newValue, oldValue) {
      if(newValue){
        this.isShow_safetyVerify_Alert = false
        this.isShow_setPass_Alert = true
      }
    },
    // 初次设置密码是否成功
    isPass_setPass(n,o){
      if(n){
        this.isShow_passVerify_Alert = true
        this.isShow_setPass_Alert = false
      }
    },
    userData(newData, oldData){
      this.isHas_password = newData.hasSetPassword;
      if (this.isHas_password) {
        this.isShow_passVerify_Alert = true;
        this.isShow_safetyVerify_Alert = false;
      } else {
        this.isShow_passVerify_Alert = false;
        this.isShow_safetyVerify_Alert = true;
      }
    }
  },
  mounted() {

    if (this.isHas_password) {
      this.isShow_passVerify_Alert = true;
    } else {
      this.isShow_safetyVerify_Alert = true;
    }
  },
  methods: {
    getPayPass(data) {
      this.payPass = data.password;
      this.$emit("getPayPass", this.payPass);
    },
    getCode(data) {
      this.isPass_safetyVerify = data.isCodePass;
      this.mobileCode = data.mobileCode;
      this.target = data.accountType;
      this.vcode = data.vcode;
    },
    handleSetPayPass(result){
      let data = {
        password: result.password,
        confirmPassword: result.confirmPassword,
        accountType: this.target,
        code: this.vcode,
      };
      this.$post(this.URL.user.uppw, data).then((res) => {
        if (res.code == 0) {
          this.isPass_setPass = true
          this.$toast(res.message);
          this.$store.dispatch('Get_userData')
        } else {
          this.$toast(res.message);
        }
      });
    },
    handleClosePopup(){
      this.$emit('hadleHideVerifyPssPopup')
    }
  },
};
</script>
